import { message, MessageType } from '@/components/message/message'
interface Option {
  label: String
  value: String
}

interface Icon {
  label: String
  options: Array<Option>
}

export const getQueryString = (name: string) => {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
  const index = window.location.hash.indexOf('?')

  const r = window.location.hash.slice(index + 1).match(reg)
  if (r != null) return trim(r[2]); return null
}

export const trim = (str: string) => {
  return str.replace(/(^s*)|(s*$)/g, '')
}

export const icons: Array<Icon> = [
  {
    label: 'System',
    options: [
      {
        label: 'Setting',
        value: 'Setting'
      },
      {
        label: 'Position',
        value: 'Position'
      }
    ]
  },
  {
    label: 'Documnet',
    options: [
      { label: 'Document', value: 'Document' },
      { label: 'Notebook', value: 'Notebook' }
    ]
  }
]

export const redirect = (href: string) => {
  href = `${location.origin}/#/${href}`
  window.open(href, 'top')
}
export const numberInput = (value: any) => {
  return value.replace(/[^\d.,]/g, '')
}
export const generateRandomPassword = (length: number) => {
  const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  let password = ''

  for (let i = 0; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * charset.length)
    password += charset[randomIndex]
  }
  return password
}
export const copyText = (msg: string) => {
  const input_dom = document.createElement('input')// 创建input元素
  input_dom.value = msg// 添加需要复制的内容到value属性
  document.body.appendChild(input_dom)// 向页面底部追加输入框
  input_dom.select()// 选择input元素
  document.execCommand('Copy')// 执行复制命令
  message('Copy successfully', MessageType.success)
}
export const loadingService = {
  lock: true,
  text: 'Loading',
  background: 'rgba(0, 0, 0, 0.7)'
}

export const getImg = (url: string) => {
  // return import.meta.env.VITE_IMG_OSS + '/' + url
  return url
}

// 获取拒绝下拉意见
export const getRemarkList = (type: string) => {
  switch (type) {
    case 'text': return [
      '内容违规'
    ]
    case 'img': return [
      '内容违规'
    ]
    case 'avatar': return [
      '头像模糊',
      '头像与本人不一致'
    ]
  }
}
